package cn.melonlib.nars.action.comp.service;

import cn.hutool.core.bean.BeanUtil;
import cn.melonlib.cores.commons.comp.service.impl.WorkerBasicService;
import cn.melonlib.cores.model.anno.WorkerComment;
import cn.melonlib.cores.model.anno.WorkerModel;
import cn.melonlib.cores.model.anno.WorkerService;
import cn.melonlib.cores.model.anno.WorkerStore;
import cn.melonlib.nars.action.model.entity.NamesRecycleBin;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

import static cn.melonlib.cores.commons.comp.service.impl.WorkerBasicService.ROOT_METHOD.*;
@Service
@WorkerComment("回收站")
@WorkerService(
        module = "action"
        ,model = @WorkerModel(
                modelType = NamesRecycleBin.class
)
        ,ignores = {SEARCH,REMOVE_BY_ID_LIST,REMOVE_BY_ID,SAVE,GET_BY_ID,TOTAL_COUNT,LIST,LOAD_ALL}
)
public class NamesRecycleBinService extends WorkerBasicService<NamesRecycleBin> {

    @WorkerStore(successTip = "清理成功",errorTip = "清理失败")
    @WorkerComment("清理回收站")
    @Transactional(value = Transactional.TxType.REQUIRED,rollbackOn = Exception.class)
    public int clean(){
        return this.dao.updateQl("delete from NamesRecycleBin where creatorId=?1",
                List.of(BeanUtil.getProperty(getIdentificationMessenger().getIdentification(),"id")));
    }

}
